import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:uuid/uuid.dart';

class UniqueIdentifierManager {
  static final UniqueIdentifierManager _instance = UniqueIdentifierManager._internal();
  factory UniqueIdentifierManager() => _instance;
  UniqueIdentifierManager._internal();

  final _storage = const FlutterSecureStorage();
  final _key = '94LivesKey';

  Future<String> getUniqueIdentifier() async {
    String? identifier = await _storage.read(key: _key);
    if (identifier != null) return identifier;

    // 生成新的 UUID 并存储
    identifier = const Uuid().v4();
    await _storage.write(key: _key, value: identifier);
    return identifier;
  }
}
